<?php
	include_once 'system/config/passwd.php';
	class siteController extends controller{
		
		public function index() {
			return parent::renderView(array("view"=>"index"));
		}
		public function login() {
			if($_POST){
				$data = $_POST['login'];
				$user = passwd::getUserAttribute("username", $data['username']);
				if(!empty($user)){
					if($user['password'] == $data['password']){
						$_SESSION['id'] = $user['id'];
						$_SESSION['username'] = $user['username'];
						parent::redirect("index");
					}else{
						parent::redirect("login&error=2");
					}
				}else{
					parent::redirect("login&error=1");
				}
			}
			return parent::renderView(array("view"=>"login"));
		}
		public function logout() {
			session_destroy();
			return parent::redirect("index");
		}
	}